package com.lnu_devteam.zongce.controller;

import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSBuilder;
import com.lnu_devteam.zongce.common.BaseResponse;
import com.lnu_devteam.zongce.common.ResultUtils;
import com.lnu_devteam.zongce.config.AliyunOssConfig;
import com.lnu_devteam.zongce.utils.OssUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author xbaozi
 * @version 1.0
 * @classname CommonController
 * @date 2023-03-25  14:19
 * @description 公共接口
 */
@Api(value = "/common", tags = {"公共接口"})
@RestController
@RequestMapping("/common")
public class CommonController {
    @Resource
    private OSS ossClient;

    @Resource
    private AliyunOssConfig config;

    private static final int MAX_BATCH_SIZE = 2;

    /**
     * @description 多图片上传，限制两张
     * @author xbaozi
     * @date 2023/3/25 15:02
     * @param multipartFileList 图片集合
     * @return BaseResponse<List<String>>   图片utl地址集合
     **/
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "List<MultipartFile>", name = "multipartFileList", value = "图片集合", required = true)
    })
    @ApiOperation(value = "多图片上传，限制两张", notes = "多图片上传，限制两张", httpMethod = "POST")
    @PostMapping("/upload")
    public BaseResponse<List<String>> upload(List<MultipartFile> multipartFileList) {
        List<String> imageUrlList = OssUtils.uploadBatch(multipartFileList, MAX_BATCH_SIZE, ossClient, config.getBucket(), config.getMarketHost());
        return ResultUtils.success(imageUrlList);
    }
}
